package cn.huhaoran.yaoyaolingxian.ui.toolWindow;

import cn.huhaoran.yaoyaolingxian.actions.newNavDestinationPageAnAction;
import cn.huhaoran.yaoyaolingxian.ui.ExportImportBranchByAFileDialog;
import cn.huhaoran.yaoyaolingxian.util.YaoYaoLingXianUtils;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.util.IconLoader;
import com.intellij.openapi.wm.ToolWindow;
import com.intellij.openapi.wm.ToolWindowFactory;
import com.intellij.ui.content.Content;
import com.intellij.ui.content.ContentFactory;

import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

public class MyToolWindowFactoryY implements ToolWindowFactory {

    @Override
    public void createToolWindowContent(Project project, ToolWindow toolWindow) {
        Icon myIcon = IconLoader.getIcon("/icons/pluginIcon16.svg", newNavDestinationPageAnAction.class);
        toolWindow.setIcon(myIcon);
        // 创建工具窗口的内容面板
        ExportImportBranchByAFileDialog exportImportBranchByAFileDialog = new ExportImportBranchByAFileDialog();
        JPanel exportJPanel =exportImportBranchByAFileDialog.getExportJPanel();
        JPanel importJPanel =exportImportBranchByAFileDialog.getImportJPanel();
/*        JButton processEncodingButton = exportImportBranchByAFileDialog.getProcessEncodingButton();
        processEncodingButton.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                YaoYaoLingXianUtils.createNewTab(toolWindow, project);
            }
        });*/
        //panel.add(new JLabel("Hello, Tool Window!"));

        // 使用新的 API 获取 ContentFactory 实例
        ContentFactory contentFactory = ContentFactory.getInstance();
        Content exportContent = contentFactory.createContent(exportJPanel, "导出本地分支到文件", false);
        Content importContent = contentFactory.createContent(importJPanel, "从本地文件导入分支", false);

        // 将内容添加到工具窗口
        toolWindow.getContentManager().addContent(exportContent);
        toolWindow.getContentManager().addContent(importContent);
    }
}
